package cn.edu.hitwh.yibao.controller;

import cn.edu.hitwh.yibao.form.MedicalInstitutionForm;
import cn.edu.hitwh.yibao.service.MedicalInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class MedicalInstitutionController {
    @Autowired
    private MedicalInstitutionService medicalInstitutionService;

    @GetMapping("/medicalInstitution")
    public String medicalInstitution() {
        return "/medicalInstitution/select";
    }

    @PostMapping("/medicalInstitution")
    public String medicalInstitutionResult(MedicalInstitutionForm medicalInstitutionForm, Model model) {
        return medicalInstitutionService.select(medicalInstitutionForm, model);
    }

    @GetMapping("/medicalInstitution/addInit")
    public String addInit(){
        return "/medicalInstitution/add";
    }

    @PostMapping("/medicalInstitution/add")
    public String add(MedicalInstitutionForm medicalInstitutionForm, Model model) {
        return medicalInstitutionService.add(medicalInstitutionForm, model);
    }

    @GetMapping("/medicalInstitution/addComplete")
    public String addComplete(Model model) {
        model.addAttribute("addResult", "添加定点医疗机构信息成功！");
        return "/medicalInstitution/select";
    }

    @GetMapping("/medicalInstitution/updateInit")
    public String updateInit(String diaId, Model model) {
        return medicalInstitutionService.updateInit(diaId, model);
    }

    @PostMapping("/medicalInstitution/update")
    public String update(MedicalInstitutionForm medicalInstitutionForm, Model model) {
        return medicalInstitutionService.update(medicalInstitutionForm, model);
    }

    @GetMapping("/medicalInstitution/updateComplete")
    public String updateComplete() {
        return "/medicalInstitution/select";
    }

    @GetMapping("/medicalInstitution/delete")
    public String delete(String diaId, Model model) {
        return medicalInstitutionService.delete(diaId, model);
    }

    @GetMapping("/medicalInstitution/deleteComplete")
    public String deleteComplete(Model model) {
        model.addAttribute("deleteResult", "删除定点医疗机构信息成功！");
        return "/medicalInstitution/select";
    }

    @GetMapping("/medicalInstitution/detail")
    public String detail(String diaId, Model model) {
        return medicalInstitutionService.detail(diaId, model);
    }
}